var mapIds = [867200310, 867200330, 867200350];
var 准备地图 = 867200280;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("副本_莫奈德_Act1_营救卡夫塔佩");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(false)
    }
    return c
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(30 * 60 * 1000)
}

function onPlayerRevived(b, a) {
    a.getAPI().enableActions();
    return false
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    em.setProperty("kill", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a)
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(c, d) {
    var b = em.getNumberProperty("kill") + 1;
    em.setProperty("kill", b);
    var a = player.getMapId();
    if (a == 867200310) {
        if (b == 3) {
            player.getAPI().spawnMob(9402246, 1, -1500, 44);
            player.getAPI().spawnMob(9402245, 1, -1500, 174);
            player.getAPI().spawnMob(9402246, 1, -1500, 177);
            player.getAPI().addPopupSay(9400585, 2000, "谢谢你！真是不给人喘气的工夫。", "", 0);
            player.getAPI().addPopupSay(9400585, 2000, "怪物从右边涌过来了！", "", 0)
        } else {
            if (b == 6) {
                player.getAPI().spawnMob(9402245, 1, -1500, 55);
                player.getAPI().spawnMob(9402246, 1, -1500, 44);
                player.getAPI().spawnMob(9402245, 1, -1500, 174);
                player.getAPI().spawnMob(9402246, 1, -1500, 177);
                player.getAPI().addPopupSay(9400583, 2000, "小心左边！", "", 0);
                player.getAPI().addPopupSay(9400583, 2000, "你那边完事了就快来帮我！", "", 0)
            } else {
                if (b == 10) {
                    player.getAPI().setNumberForQuestInfo(64015, "chk1", 1);
                    player.getAPI().addPopupSay(9400585, 5000, "呼哧呼哧！多亏你帮忙，差不多都打退了。\r麻烦你去救出那边被屋顶压住的村民！", "", 0)
                } else {
                    if (b == 12) {
                        player.getAPI().addPopupSay(9400581, 2000, "#face1#该死，哪儿来这么多怪物，没完没了的……", "", 0);
                        player.getAPI().spawnMob(9402241, 1, -847, 255);
                        player.getAPI().spawnMob(9402314, 1, -234, 303);
                        player.getAPI().spawnMob(9402241, 1, -841, 256);
                        player.getAPI().spawnMob(9402314, 1, -612, 291)
                    } else {
                        if (b == 14) {
                            player.getAPI().killMob(9402323);
                            player.getMap().spawnReactorIfNotExist(8659133, 0, 407, 224, 0, "64014_chk4");
                            player.getMap().spawnReactorIfNotExist(8659134, 0, 1153, 204, 0, "64014_chk5");
                            player.getAPI().setNumberForQuestInfo(64015, "chk3", 1)
                        }
                    }
                }
            }
        }
    } else {
        if (a == 867200350) {
            if (d == 9402266) {
                player.getAPI().openNpc(3, "莫奈德_Act1_营救卡夫塔佩");
                em.setProperty("clear", 1)
            }
        }
    }
    return 1
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
};